
import geoip2.database
reader = geoip2.database.Reader('./assets/GeoLite2-City.mmdb')

def GetProvince(ip : str):

    response = reader.city(ip)

    return response.subdivisions.most_specific.names["zh-CN"]

def GetCity(ip : str):

    response = reader.city(ip)

    return response.city.names["zh-CN"]

def GetProvinceAndCity(ip : str):

    try:
        response = reader.city(ip)
        return f'{response.subdivisions.most_specific.names["zh-CN"]} {response.city.names["zh-CN"]}'
    except:
        return '未知'
